package stu.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import stu.cms.exection.BaseException;
import stu.cms.exection.OperationConstant;
import stu.cms.exection.ValidException;
import stu.cms.pojo.entity.Dept;
import stu.cms.mapper.DeptMapper;
import stu.cms.result.PageResult;
import stu.cms.service.DeptService;
import stu.cms.utils.InfoKit;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    /**
     * 分页查询部门信息
     * @param dept
     * @return
     */
    public PageResult<Dept> pageSelect(Dept dept) {
        return null;
    }

    /**
     * 保存部门信息
     * @param dept
     */
    public void saveDept(Dept dept) {
        //所有字段非空验证,并且通过反射赋值
        try {
            boolean flag= InfoKit.isValidAll(dept);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new ValidException(e.getMessage());
        }

        if(!this.saveOrUpdate(dept)){
            throw new BaseException(OperationConstant.SAVE);
        }
    }


    /**
     * 删除部门信息
     * @param id
     */
    public void removeDept(Integer id) {
        if(!this.removeById(id))
            throw new BaseException(OperationConstant.DELETE);
    }
}
